<template>
  <h1>员工列表综合练习</h1>
<el-form style="width: 600px;margin: 0 auto;" >
  <el-form-item label="姓名">
    <el-input placeholder="请输入员工姓名" v-model="pro.name"></el-input>
  </el-form-item>
  <el-form-item label="工资">
    <el-input placeholder="请输入员工工资" v-model="pro.salary"></el-input>
  </el-form-item>
  <el-form-item label="岗位">
    <el-input placeholder="请输入员工岗位" v-model="pro.job"></el-input>
  </el-form-item>
  <el-form-item>
    <el-button type="success" @click="add" >提交</el-button>
  </el-form-item>
</el-form>
  <el-table :data="arr" style="width: 600px;margin:0 auto;">
    <el-table-column label="编号" type="index" width="80" align="center"></el-table-column>
    <el-table-column label="姓名" prop="name" align="center"></el-table-column>
    <el-table-column label="工资" prop="salary" align="center"></el-table-column>
    <el-table-column label="岗位" prop="job" align="center"></el-table-column>
    <el-table-column label="操作" align="center">
      <template #default="myscope">
        <el-button type="danger" @click="del(myscope.$index,myscope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>

</template>

<script setup>
import {ref} from "vue";
import {ElMessage} from "element-plus";

const pro = ref({name:'',salary:'',job:''});
const arr = ref([]);
const add = ()=>{
  if (pro.value.name.trim()==''||pro.value.salary.trim()==''||pro.value.job.trim()==''){
    ElMessage.error('数据不能为空')
    return;
  }
  arr.value.push(pro.value);
  pro.value={name: '', salary: '', job: ''};
}
const del =(index,row)=>{
  if (confirm('你确认要删除'+row.name+'吗')){
    arr.value.splice(index,1);
    ElMessage.success(row.name+'已删除成功!')
  }
}

</script>


<style scoped>

</style>